home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / CALLERS.SCR < prev    next >
Text File  |  1993-02-01  |  8KB  |  186 lines

  1.  
  2. // CALLERS.SCR  --  Maximus Today's Callers Report Generator  --  Version 1.00
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6.  
  7. // CALLERS scans the Maximus USER.BBS file, and writes an 'avatar' *.BBS
  8. // file for online display. It lists all accounts accessed for the current
  9. // date, in time sorted order. There are no command line parameters, edit
  10. // the following entries to suit your system.
  11.  
  12. char *rfile = "C:\\BBS\\MISC\\CALLERS.BBS"; // Path & name of report file
  13. //char *ufile = "USER.BBS";                 // Path & name of Maximus user file
  14. char *ufile = "C:\\BBS\\USER.BBS";          // Path & name of Maximus user file
  15.  
  16. // AVAILABLE COLOUR CONSTANTS
  17. // Foreground & Background:
  18. // BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LGREY
  19. // Foreground ONLY:
  20. // DGREY, LBLUE, LGREEN, LCYAN, LRED, LMAGENTA, YELLOW, WHITE
  21.  
  22. char COLOURHEAD = WHITE;                    // Report headline colour
  23. char COLOURHUND = LRED;                     // Report underline colour
  24. char COLOURBOXB = CYAN;                     // Report box colour
  25. char COLOURLABL = LCYAN;                    // Report box label colour
  26. char COLOURLABB = BLUE;                     // Report box label bg colour
  27. char COLOUROPT1 = YELLOW;                   // Highlight colour one
  28. char COLOUROPT2 = LGREEN;                   // Highlight colour two
  29. char COLOURDATA = LGREY;                    // Report data colour
  30.  
  31. char *banner = "CALLERS v1.00";             // Script banner
  32. char *desc = "Today's Callers Reporter";    // Description
  33. char MCLS=0x0C;                             // Avatar 'clear screen'
  34. char MENTER=0x01;                           // Maximus 'press enter'
  35.  
  36. long fp;                                    // Report file handle
  37.  
  38. main ()                                     // Main program
  39. {
  40.     printf ("\n%s - %s\n\n",banner,desc);   // Announce
  41.  
  42.     if (!BaseOpenR (ufile)) {
  43.         printf ("ERROR opening user file %s\n",ufile);
  44.         saybibi (); exit ();
  45.     }
  46.  
  47.     sortufile ();                           // Sort in date order
  48.     writereport ();                         // Write output report
  49.  
  50.     BaseClose ();                           // Close the user base
  51.     saybibi ();                             // Was it good for you too?
  52. }
  53.  
  54. sortufile ()                                // Sort in date order
  55. {
  56.     printf ("Collecting today's callers ");
  57.     BaseSort (IDX_DATE);                    // Sort the base by last call date
  58.     printf ("\n");
  59. }
  60.  
  61. readerror ()                                // Report a user base read problem
  62. {
  63.     printf ("\nERROR reading user file\n");
  64.     fclose (fp); return;
  65. }
  66.  
  67. writereport ()                              // Write the .BBS report file
  68. {
  69.     int i, rec=1, calls=0;
  70.     long ttime=0;
  71.     char colourhead[5], colourhund[5], colourboxb[5], colourdata[5];
  72.     char colouropt1[5], colouropt2[5], colourlabl[5];
  73.     char *head=" - TODAY'S CALLERS REPORT - ";
  74.     char *line="                ─────────────────────────────────────────────\n";
  75.     char *b1 =   "┌───────────────────────────┬───────────";
  76.     char *b2 =   "───────────────┬───────┬───────┬──────┐\n";
  77.     char *c1 =   "├───────────────────────────┼───────────";
  78.     char *c2 =    "───────────────┼───────┼───────┼──────┤\n";
  79.     char *d1 =   "└───────────────────────────┴───────────";
  80.     char *d2 =   "───────────────┴───────┴───────┴──────┘\n";
  81.  
  82.     fp=fopen (rfile,"wb");                  // Open report file
  83.     if (fp==NULL) return;
  84.  
  85.     printf ("Writing report file \"%s\" ",rfile);
  86.  
  87.     // The Avt() function returns a pointer to a static character array
  88.     // containing the requested avatar characters. The following strcpy's
  89.     // save the requested strings for later use. This IS specifically
  90.     // required to allow more than one colour sequence as an (f)printf
  91.     // parameter. The unseen trap that this avoids, is that all function
  92.     // call parameter data is interpreted at _function call_ time. The
  93.     // result of multiple avt() references in a (f)printf parameter list
  94.     // is that the data from the _last_ avt() call would be used for all
  95.     // references <grumble>.
  96.  
  97.     // Get avatar colour strings
  98.     strcpy (colourhead,Avt (COLOURHEAD)); strcpy (colourhund,Avt (COLOURHUND));
  99.     strcpy (colourboxb,Avt (COLOURBOXB)); strcpy (colourdata,Avt (COLOURDATA));
  100.     strcpy (colouropt1,Avt (COLOUROPT1)); strcpy (colouropt2,Avt (COLOUROPT2));
  101.     strcpy (colourlabl,Avt (COLOURLABL,COLOURLABB));
  102.  
  103.     // Output CLS, MoreOff, heading and underline
  104.     fputc (MCLS,fp);
  105.     fprintf (fp,"%s                MUL v%s%s%s\n",
  106.         colourhead,VERSN,head,DateToStr (SysDate ()));
  107.     fprintf (fp,"%s%s",colourhund,line);
  108.  
  109.     fprintf (fp,"%s%s%s",colourboxb,b1,b2); // Output box top
  110.  
  111.     // Output box heading
  112.     fprintf (fp,"│%s CALLER                    %s",colourlabl,colourboxb);
  113.     fprintf (fp,"│%s LOCATION                 %s",colourlabl,colourboxb);
  114.     fprintf (fp,"│%s CALLS %s",colourlabl,colourboxb);
  115.     fprintf (fp,"│%s LOGON %s",colourlabl,colourboxb);
  116.     fprintf (fp,"│%s USED %s│\n",colourlabl,colourboxb);
  117.  
  118.     fprintf(fp,"%s%s",c1,c2);               // Output box divider
  119.  
  120.     // Output first data line
  121.     while (TRUE) {
  122.         if (!BaseRead (rec++)) { readerror(); return; } // Find record
  123.         if (!BaseDaysLCall () && USRpriv!=SYSOP) {
  124.             fprintf (fp,"│ %s",colouropt2);
  125.  
  126.             fprintf (fp,"%-25s %s│ %s",USRname,colourboxb,colouropt2);
  127.             fprintf (fp,"%-24s %s│ %s",USRcity,colourboxb,colouropt2);
  128.             fprintf (fp,"%5u %s│ %s",USRcalls,colourboxb,colouropt2);
  129.             fprintf (fp,"%5s %s│ %s",
  130.                 TimeToStr (USRlutime),colourboxb,colouropt2);
  131.             fprintf (fp,"%4u %s│\n",USRtimetoday,colourboxb);
  132.             ttime=ttime+USRtimetoday;
  133.             ++calls;
  134.             break;
  135.         }
  136.         if (rec > BaseCount()) break;
  137.     }
  138.  
  139.     // Output the remaining data
  140.     while (TRUE) {
  141.         if (rec > BaseCount()) break;
  142.         if (!BaseRead (rec++)) { readerror(); return; } // Find record
  143.         if (BaseDaysLCall ()) break;
  144.  
  145.         if (USRpriv!=SYSOP) {
  146.             fprintf (fp,"│ %s",colourdata);
  147.  
  148.             fprintf (fp,"%-25s %s│ %s",USRname,colourboxb,colourdata);
  149.             fprintf (fp,"%-24s %s│ %s",USRcity,colourboxb,colourdata);
  150.             fprintf (fp,"%5u %s│ %s",USRcalls,colourboxb,colourdata);
  151.             fprintf (fp,"%5s %s│ %s",
  152.                 TimeToStr (USRlutime),colourboxb,colourdata);
  153.             fprintf (fp,"%4u %s│\n",USRtimetoday,colourboxb);
  154.             ttime=ttime+USRtimetoday;
  155.             ++calls;
  156.         }
  157.     }
  158.  
  159.     fprintf(fp,"%s%s",c1,c2);               // Output box divider
  160.  
  161.     // Totals
  162.     fprintf (fp,"│ %s",colourhead);
  163.     fprintf (fp,"Totals        %s%5u calls %s│",colouropt1,calls,colourboxb);
  164.     fprintf (fp,"                          │       │       │");
  165.     fprintf (fp,"%s%5lu %s│\n",colouropt1,ttime,colourboxb);
  166.  
  167.     // Output lower box border
  168.     fprintf (fp,"%s%s%s",colourboxb,d1,d2);
  169.  
  170.     // Press Enter prompt and CLS
  171.     fprintf (fp,"%s%c",Avt (WHITE,BLACK),MENTER);
  172.     fprintf (fp,"%s%c",Avt (LGREY,BLACK),MCLS);
  173.  
  174.     fclose (fp);                            // Close report file
  175.     putch ('\n');                           // End notify
  176. }
  177.  
  178. // Byebye
  179. saybibi ()
  180. {                             
  181.     puts ("\nCallers done!\n");
  182. }
  183.  
  184. // End of script
  185.  
  186.